package com.spark.core

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

import java.io.File

object Demo1WordCount3 {

  def main(args: Array[String]): Unit = {
    /**
     * 1、创建spark环境
     */
    //spark环境配置对象
    val conf = new SparkConf()

    //设置spark任务的名称
    conf.setAppName("wordcount")
    //设置spark运行模式，local:本地运行
    conf.setMaster("local")

    //创建spark上下文对象，sc是spark写代码的入口
    val sc = new SparkContext(conf)

    // 日志级别
    sc.setLogLevel("error")

    val words = sc.textFile("/data/words.txt")
    words.cache()
    words.collect().foreach(println)
    words.foreach(println)
  }
}
